package com.yjhb.android.sbz.mvp.dailysign;

import com.yjhb.android.sbz.entity.TodayClockParam;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.math.BigDecimal;

/**
 * 创建者 zx
 * 创建时间 2021/1/12 10:36
 */
public class DailySignPresenter extends ConventionPresenter<DailySignView> {
    private final String TAG = "DailySignPresenter";

    @Override
    protected void onDestroy() {

    }

    public DailySignPresenter(DailySignView dailySignView) {
        super(dailySignView);
    }


    /**
     * 打卡信息
     */
    public void getJoinClockChallengeCount() {
//        if (view != null) {
//            view.onWait("加载中...");
//        }
        HttpTool.request(model.getJoinClockChallengeCount(), new HttpObserver<TodayClockParam>() {
            @Override
            public void onResult(TodayClockParam data) {
                if (view != null) {
                    view.onInfo(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    /**
     * 报名打卡挑战
     *
     * @param type
     * @param money
     */
    public void joinClockChallenge(Integer type, BigDecimal money) {
        if (view != null) {
            view.onWait("处理中...");
        }
        HttpTool.request(model.joinClockChallenge(type, money), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onSuccess(0, "报名成功~~别忘了明早打卡哦~");
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

    /**
     * 打卡
     *
     **/
    public void clock() {
        if (view != null) {
            view.onWait("正在打卡...");
        }
        HttpTool.request(model.clock(), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onSuccess(1, "打卡成功~~等候瓜分奖励吧！");
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }
}
